from PySide6.QtGui import QClipboard, QTextDocument
from PySide6.QtWidgets import QApplication, QDialog
from PySide6.QtCore import Slot

from .ui_text_dialog import Ui_Dialog


class TextDialog(QDialog):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.text = self.ui.text
        doc = QTextDocument(self.text)
        self.text.setDocument(doc)
        self.doc = doc
        self.raw_text = ''

    def set_text(self, text: str):
        self.raw_text = text
        self.doc.setPlainText(text)
    
    # override
    @Slot()  # type: ignore
    def accept(self) -> None:
        b = QApplication.clipboard()
        b.setText(self.raw_text)
        super().accept()
